package com.lala.controller;

import com.lala.entity.ClientNews;
import com.lala.service.ClientNewsService;
import com.lala.util.ResultJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 霍明铭
 * @date 2020/3/27 15:04
 */
@Controller
@RequestMapping("/clientnews")
public class ClientNewsController {
@Autowired
    ClientNewsService newsService;
    @GetMapping("/news")
    @ResponseBody
    public ResultJson getNews(Integer userId,Integer status){
     try {
         List<ClientNews>news= newsService.getNews(userId,status);
         return new ResultJson(200,"成功",news);
     }catch (Exception e){
         return  new ResultJson(500,"成功",null);
     }


    }
      @GetMapping("/read")
      @ResponseBody
    public ResultJson read(Integer userId){
     try {
         List<ClientNews>wdNews= newsService.getWdNews(userId);
         return new  ResultJson(200,"成功",wdNews);
     }catch (Exception e){
         return new  ResultJson(500,"失败",null);
     }
    }
    @GetMapping("/upRead")
    @ResponseBody
    public ResultJson upRead(Integer id){
        System.out.println(id);
        try {
           newsService.upNews(id);
            return new  ResultJson(200,"成功",null);
        }catch (Exception e){
            return new  ResultJson(500,"失败",null);
        }
    }


}
